package org.jsola.hr.helper;

import org.jsola.hr.dto.ChannelGroupUserAddDTO;
import org.jsola.hr.dto.ChannelGroupUserUpdateDTO;
import org.jsola.hr.entity.ChannelGroupUserDO;
import org.jsola.hr.query.ChannelGroupUserQuery;
import org.jsola.hr.service.IChannelGroupUserService;
import org.jsola.hr.vo.ChannelGroupUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 渠道分组用户中间表
 *
 * @author zhr
 */
@Component
public class ChannelGroupUserTestHelper extends BaseTestHelper {
    
    @Autowired
    private IChannelGroupUserService channelGroupUserService;

    /**
     * 生成add测试数据
     * @return ChannelGroupUserAddDTO
     */
    public ChannelGroupUserAddDTO getChannelGroupUserAddDTO(){
        ChannelGroupUserAddDTO channelGroupUserAddDTO = new ChannelGroupUserAddDTO();
        channelGroupUserAddDTO.setChannelGroupId(getRandomValue("varchar",32));
        channelGroupUserAddDTO.setUserId(getRandomValue("varchar",32));
        return channelGroupUserAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ChannelGroupUserUpdateDTO
     */
    public ChannelGroupUserUpdateDTO getChannelGroupUserUpdateDTO(ChannelGroupUserVO channelGroupUserVO){
        return channelGroupUserService.selectDOById(channelGroupUserVO.getId(), SITE_ID).to(ChannelGroupUserUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ChannelGroupUserQuery
     */
    public ChannelGroupUserQuery getChannelGroupUserQuery() {
        ChannelGroupUserQuery channelGroupUserQuery = new ChannelGroupUserQuery();
        List<ChannelGroupUserDO> channelGroupUserDOList = channelGroupUserService.list(new ChannelGroupUserDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(channelGroupUserDOList)) {
            ChannelGroupUserDO channelGroupUserDO = channelGroupUserDOList.get(0);
            channelGroupUserQuery = channelGroupUserDO.to(ChannelGroupUserQuery.class);
        }
        return channelGroupUserQuery;
    }

    /**
     * 保存示例
     * @return ChannelGroupUserVO
     */
    public ChannelGroupUserVO saveChannelGroupUserExample(){
        ChannelGroupUserAddDTO addDTO = this.getChannelGroupUserAddDTO();
        ChannelGroupUserVO channelGroupUserVO = channelGroupUserService.save(addDTO,buildTokenUser());
        return channelGroupUserVO;
    }


}

